home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / dld-3_23.lha / dld-3.2.3 / ref.c < prev    next >
C/C++ Source or Header  |  1991-05-30  |  2KB  |  61 lines

  1. /* ref.c -- explicitly make a reference to a symbol so that the library
  2.    defining this symbol is loaded. */
  3.  
  4. /* This file is part of DLD, a dynamic link/unlink editor for C.
  5.    
  6.    Copyright (C) 1990 by W. Wilson Ho.
  7.  
  8.    The author can be reached electronically by how@cs.ucdavis.edu or
  9.    through physical mail at:
  10.  
  11.    W. Wilson Ho
  12.    Division of Computer Science
  13.    University of California at Davis
  14.    Davis, CA 95616
  15.  */
  16.  
  17. /* This program is free software; you can redistribute it and/or modify it
  18.    under the terms of the GNU General Public License as published by the
  19.    Free Software Foundation; either version 1, or (at your option) any
  20.    later version. */
  21.  
  22. #include "defs.h"
  23.  
  24. /*
  25.  *  explicitly create a reference to NAME so that a library routine
  26.  *  defining it is forced to be loaded.  (c.f. "ld -u" option)
  27.  *  It has no effect on non-library routines (plain object files).
  28.  */
  29. dld_create_reference (name)
  30. char *name;
  31. {
  32.     register char *p = 0;
  33.     struct nlist dummy_nlist;        /* simulate a nlist entry so that
  34.                        _dld_entery_global_ref can be used. */
  35.     
  36.     if (name == 0)
  37.     return 0;
  38.  
  39.     if (setjmp (_dld_env)) {
  40.     if (p) free (p);
  41.     return dld_errno;
  42.     }
  43.  
  44.     if (_dld_dummy_entry == 0)
  45.     _dld_create_dummy_entry ();
  46.  
  47.     bzero (&dummy_nlist, sizeof (struct nlist));
  48.  
  49.     p = (char *) _dld_malloc (strlen(name) +2);
  50.     *p = '_';
  51.     strcpy (p+1, name);
  52.  
  53.     dummy_nlist.n_un.n_name = p;
  54.     dummy_nlist.n_type = N_EXT | N_UNDF;
  55.  
  56.     _dld_enter_global_ref (_dld_dummy_entry, &dummy_nlist, p);
  57.        
  58.     free (p);
  59.     return 0;
  60. } /* dld_create_reference */
  61.